<%@ page language="java" import="com.siysoft.tc.base.bean.to.User" pageEncoding="UTF-8"%>


<!--申请预约流程单-->
<div class="reservation_window">
	<div class="onclose">x</div>
    <div class="t">Which kind of reservation do you want ?</div>
    <div class="buttonLink">
    	<span class="exam">Exam</span><span class="assignment">Assignment</span><span class="assignment">Other</span>
    </div>
</div>

<div class="newContentTab" style="display:none">
	<div class="title">Reservation Dtails</div>
    <div class="newContent-tab">
    	<ul>
        	<li class="on"><span>Details</span></li>
            <li class=""><span>Chatting</span></li>
            <li class=""><span>Member</span></li>
        </ul>
    </div>
    <!-- Details -->
    <div class="newContentTabCont" style="display: block;">
    	<div class="online">
        	<span>●</span>
            <span>●</span>
            <span>●</span>
            <span>●</span>
        </div>
        <div class="ev_tap">
        	<ul class="reservation_flow">
            	<li><span class="red">Paid</span></li>
            	<li><span class="green">Begin</span></li>
            	<li><span class="blue">Finish</span></li>
            	<li><span class="purple">Evaluate</span></li>
            </ul>    
        </div>
        <div class="ev-formCont">
        	<div class="new_reservation_show">
        		<ul>
					<li class="text"><span class="dis">University:</span> <c id="new_reservation_school"></c></li>
					<c class="apply_lecture"><li title="lecture"><span class="dis" >Lecturer:</span><input type="text" class="input"></li></c>
					<li title="CCCCCCCourse" class="formImportantLi"><span class="dis" style="float:left"><span style="color:red">*</span> Course:</span>
						<select class="input new_reservation_course" name="course" style="float:left"></select>
					</li>
					<li class="Class_Size" title="MMMMMMMaximum"><span class="dis"><span style="color:red">*</span> Max <br/>Class Size:</span><input type="text" class="input new_reservation_maximum" name="max_size" onblur="judgeDigit(this)"></li>
					<li title="AAAAAAAddress"><span class="dis"><span style="color:red">*</span> Address:</span><input type="text" class="input new_reservation_address" name="address"></li>
					<li title="TTTTTTTime"><span class="dis" style="float:left"><span style="color:red">*</span> Time:</span><input type="text" class="input new_reservation_time" name="time" readonly="readonly" onclick="SelectDate(this,'yyyy-MM-dd hh:mm:ss')"></li>
					<li title="PPPPPPPeriod"><span class="dis"> Period:</span><input type="text" class="input new_reservation_period" name="period" onblur="judgeDigit(this)"></li>
					<c id="new_reservation_which_goal">
						<li title="GGGGGGGoal"><span class="dis" style="float:left"><span style="color:red">*</span> Goal:</span>
							<select class="input new_reservation_goal" name="goal">
							<option value="60">pass</option>
							<option value="80">more than pass</option>
							</select>
						</li>
					</c>
					<li title="HHHHHHHourly Payment"><span class="dis" style="float:left">Total Payment:</span><input type="text" class="input new_reservation_wage" name="wage" style="float:left;width:125px" onblur="judgeDigit(this)"><span style="float:left;margin-left:5px">￡</span></li>
					<li title="BBBBBBBBBonus" style="clear:both"><span class="dis" style="float:left;">Bonus:</span><span id="BonusRadio"><input type="radio" name="isbonus" value="personal" id="Bonusyes"><span style="" >Yes</span> &nbsp;&nbsp;<input type="radio" name="isbonus" checked="checked" value="public" id="Bonusno"> <span style="">No</span></span></li>
					<li style="margin-left:115px;display:none;clear:both"  id="BonusInput"><span ><input type="text" class="input new_reservation_bonus" name="bonus" style="float:left;width:125px" value="0" onblur="judgeDigit(this)"><span style="float:left;margin-left:5px">￡</span></li>
					<li title="PPPPPPublic" class="text" style="clear:both"><span class="dis"></span><input type="radio" name="ispublic" value="personal"> Personal &nbsp;&nbsp;<input type="radio" name="ispublic" checked="checked" value="public"> Public</li>
					<li title="AAAAAdimistrator" class="text"><span class="dis"></span><input name="administrator" type="checkbox" value="administrator"> Send to Administrator</li>
					
          		</ul>
          		<div class="ev-button-wrap">
                	<input type="submit" value="SUBMIT" class="ev-button-grop new_reservation_confirm">
                </div>
           </div>
           <div class="reservation_detail_show">
				<ul>
                	<li><span class="dis">Reservation Code:</span><c id="reservation_detail_reservation_number"></c></li>
                    <li><span class="dis">University:</span><c id="reservation_detail_school"></c></li>
                	<li><span class="dis">Lecturer:</span><c id="reservation_detail_lecture"></c></li>
                    <li><span class="dis">Course:</span><c id="reservation_detail_course"></c></li>
                    <li><span class="dis">Maximum <br>Class Size:</span><c id="reservation_detail_max_size"></c></li>
                    <li><span class="dis">Address:</span><c id="reservation_detail_address"></c></li>
                    <li><span class="dis">Time:</span><c id="reservation_detail_time"></c></li>
                    <li><span class="dis">Period:</span><c id="reservation_detail_period"></c></li>
                    <li><span class="dis">Goal:</span><c id="reservation_detail_goal"></c></li>
                    <li><span class="dis">Total Payment:</span><c id="reservation_detail_wage"></c></li>
                    <li><span class="dis">Bonus:</span><c id="reservation_detail_bonus"></c></li>
                    <li><span class="dis">Type:</span><c id="reservation_detail_ispublic"></c></li>
 
                </ul>
	            <div class="ev-button-wrap">
	            	<input type="submit" value="JOIN IT" class="ev-button-grop reservation_detail_button">
	            	<div class="classType reservation_detail_writting"></div>
	            	<span class="exit" id="reservation_detail_exit"><span class="glyphicon glyphicon-log-out"></span></span>
	            </div>
           </div>
        </div>
    </div>
    <!-- Chatting -->
    <div class="newContentTabCont" style="display: none;">
        <div class="newContentTabCont2">
        	<div class="no-chatting">there is no chatting</div>
            <div class="comm_cont">
                <ul id="reservation_chat_list">
                </ul>
            </div>
            <div class="send">
              <input type="text" class="input" value="Leave a message?" id="reservation_chat_content">
                <button class="button" id="reservation_chat_send">SEND</button>
            </div>
        </div>     
    </div>
    <!-- Member -->
    <div class="newContentTabCont" style="display: none;">
    	<div class="no-member">there is no member</div>
    	<div class="newContentTabCont3">
        	<p class="t">Teacher</p>
        	<ul id="reservation_detail_lecture_list">
            </ul>
            <div class="evaluate_big_cont" style="display:none">
			    <div class="range_t">Average Scores:</div>
			    <div class="evaluate_range">
			    	<ul class="evaluate_com_list evaluate_com_list1">
			    		<li>
			            	<div class="t">Patience:</div>
			                <div class="outer">
			                	<div class="inner" id="evaluate_page_teacher_all_pat_1" style="width:20%"></div>
			                </div>
			                <div class="n" id="evaluate_page_teacher_all_pat">30</div>
			            </li>
			            <li>
			            	<div class="t">Professionalism:</div>
			                <div class="outer">
			                	<div class="inner" id="evaluate_page_teacher_all_pro_1" style="width:20%"></div>
			                </div>
			                <div class="n" id="evaluate_page_teacher_all_pro">30</div>
			            </li>
			            <li>
			            	<div class="t">Expression:</div>
			                <div class="outer">
			                	<div class="inner" id="evaluate_page_teacher_all_exp_1" style="width:20%"></div>
			                </div>
			                <div class="n" id="evaluate_page_teacher_all_exp">30</div>
			            </li>
			            <li>
			            	<div class="t">Usefulness:</div>
			                <div class="outer">
			                	<div class="inner" id="evaluate_page_teacher_all_use_1" style="width:20%"></div>
			                </div>
			                <div class="n" id="evaluate_page_teacher_all_use">30</div>
			            </li>
			            <li>
			            	<div class="t">Interaction:</div>
			                <div class="outer">
			                	<div class="inner" id="evaluate_page_teacher_all_int_1" style="width:20%"></div>
			                </div>
			                <div class="n" id="evaluate_page_teacher_all_int">30</div>
			            </li>
			        </ul>
			    </div>
			    <div class="evaluate_range_other" id="evaluate_page_teacher_all_list">
			    </div>
		    </div>
            <p class="t">Student</p>
        	<ul id="reservation_detail_student_list">
            </ul>
    </div>
</div>
</div>






<!--评价-->

<div class="evaluate_page_praise" id="evaluate_page_teacher">
  	<div class="evaluate_head">
    	<div class="t">Evaluate</div> 
    </div>
    <div class="evaluate_praise_cont">
    	<ul class="evaluate_praise_list" id="evaluate_page_teacher_list">
        	<li>
            	<span><img src="<%=request.getContextPath()%>/common/images/photo.png" class="photo"></span><textarea name="" cols="" rows="" class="textarea"></textarea>
                <span class="glyphicon glyphicon-thumbs-up"></span><span class="glyphicon glyphicon-thumbs-down"></span>
            </li>
            <li>
            	<span><img src="<%=request.getContextPath()%>/common/images/photo.png" class="photo"></span><textarea name="" cols="" rows="" class="textarea"></textarea>
                <span class="glyphicon glyphicon-thumbs-up"></span><span class="glyphicon glyphicon-thumbs-down"></span>
            </li>
        </ul>
        <div class="submit"><input type="button" id="evaluate_page_teacher_submit" value="Submit"></div>
    </div>
</div>

<div class="evaluate_page" id="evaluate_page_student">
  	<div class="evaluate_head">
    	<div class="t"><img class="photo" src="<%=request.getContextPath()%>/common/images/photo.png"></div> 
    </div>
    <div class="evaluate_pagecont">
    	<div class="tap" id="evaluate_page_student_content" contenteditable="true">SAY SOMETHING ......</div>
		<div class="evaluate_demo">
			<span class="test">Patience:</span>
			<input type="hidden" class="single-slider" id="evaluate_page_student_pat" value="60" style="display: none;">
		    <div class="slider-container theme-green"></div>			
		</div>
		<div class="evaluate_demo">
			<span class="test">Professionalism:</span>
			<input type="hidden" class="single-slider" id="evaluate_page_student_pro" value="60" style="display: none;">
		    <div class="slider-container theme-green"></div>			
		</div>
		<div class="evaluate_demo">
			<span class="test">Expression:</span>
			<input type="hidden" class="single-slider" id="evaluate_page_student_exp" value="60" style="display: none;">
		    <div class="slider-container theme-green"></div>			
		</div>
		<div class="evaluate_demo">
			<span class="test">Usefulness:</span>
			<input type="hidden" class="single-slider" id="evaluate_page_student_use" value="60" style="display: none;">
		    <div class="slider-container theme-green"></div>			
		</div>
		<div class="evaluate_demo">
			<span class="test">Interaction:</span>
			<input type="hidden" class="single-slider" id="evaluate_page_student_int" value="60" style="display: none;">
		    <div class="slider-container theme-green"></div>			
		</div>
		<div class="submit"><input type="button" id="evaluate_page_student_submit" value="Submit"></div>
        
    </div>
</div>


<!-- evaluate after reservation -->
<div class="reservation_detail_evaluate_page">
<div class="layer_button">
	<div class="title">Do  you  want to  evaluate someone else?</div>
	<div class="button"><input type="button" value="Yes" id="evaluate_yes"><input type="button" value="No" id="evaluate_no"></div>
</div>
</div>
<!--reach goal-->
<div class="dropOut2" id="evaluate_reach_goal">
	<div class="title">Do you reach your goal?</div>
    <div class="button">
    	<a href="javascript:;" class="yes">Yes</a>
        <a href="javascript:;" class="no">No</a>
    </div>
</div>

<!--drop out-->
<div class="dropOut">
	<div class="title">Do you really want to drop out?</div>
    <div class="button">
    	<a href="javascript:;" class="yes" id="drop_out">Yes</a>
        <a href="javascript:;" class="no">No</a>
    </div>
</div>

<!--2016 10 24新增-->
<div class="appley_for_teacher" style="display:none">
	<div class="name">
    	<p>APPLY FOR THE TEACHER</p>
        <p>▼</p>
    </div>
    <form>
    	<div class="cont">
        <ul class="">
            <li><span class="dis">Total Payment</span><input type="text" id="apply_for_teacher_wage"></li>
            <li><span class="dis">Period</span><input type="text" id="apply_for_teacher_period"></li>
        </ul>
        <div class="submit"><input type="submit" value="SUBMIT" id="apply_for_teacher_submit"></div>
        </div>
    </form>
</div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="<%=request.getContextPath()%>/common/js/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<%=request.getContextPath()%>/common/js/bootstrap.min.js"></script>

    
    <!--轮播图-->
    <script src="<%=request.getContextPath()%>/common/js/jquery.flexslider-min.js"></script>
    <script src="<%=request.getContextPath()%>/common/js/index.js"></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/common/js/jquery.range.js"></script>


    
    <script>


var user_type = <%=us.getUser_type() %>;
var user_id = <%=us.getUser_id() %>;
var user_name = '<%=us.getUser_name() %>';

function evaluate_student(user_id, reservation_id, patience
		, professionalism, expression, usefulness, interaction,
		content, isgoal){
	$.ajax({
		type:"post",
		url:"<%=request.getContextPath()%>/app/reservation/evaluatestudent.htm",
		data:{
			"student_id":user_id,
			"reservation_id":reservation_id,
			"patience":patience,
			"professionalism":professionalism,
			"expression":expression,
			"usefulness":usefulness,
			"interaction":interaction,
			"detail":content,
			"isgoal":isgoal,
		},
		async:false,
		success:function(data){
			alert(data.data.result);
			$("#evaluate_page_student").hide();
			$(".reservation_detail_evaluate_page").hide();
		}
	});
}

function course_list(teacher_name){
	if(user_type == 1 || teacher_name != ""){
		if(user_type == 1) teacher_name = user_name;
		$.ajax({
			type:"get",
			url:"user/teacher_course_list.htm",
			data:{
				"teacher_name":teacher_name,
				"limit":-1,
				"offset":-1
			},
			async:false,
			success:function(data){
				var interest = data.data.interest;
				var new_reservation_course_html = "";
				for(var i = 0; i < interest.length; i++){
					new_reservation_course_html = new_reservation_course_html
					+ '<option>' + interest[i].interest_name + '</option>';
				}
				$(".new_reservation_course").html(new_reservation_course_html);
			}
		});
	}
	else{
		$.ajax({
			type:"get",
			url:"user/interest.htm",
			data:{
				"limit":-1,
				"offset":-1
			},
			async:false,
			success:function(data){
				var interest = data.data.interest;
				var new_reservation_course_html = "";
				for(var i = 0; i < interest.length; i++){
					new_reservation_course_html = new_reservation_course_html
					+ '<option>' + interest[i].interest_name + '</option>';
				}
				$(".new_reservation_course").html(new_reservation_course_html);
			}
		});
	}
}

$(".reservation_window .exam").on("click",function(){
	$(".reservation_window").hide();
	$("#new_reservation_school").html(user_school_confirm);
	var new_reservation_which_goal_html = 
		'<li title="GGGGGGGoal"><span class="dis" style="float:left"><span style="color:red">*</span> Goal:</span>'
        + '<select class="input new_reservation_goal" name="goal">'
        + '<option value="60">pass</option>'
        + '<option value="80">more than pass</option>'
        + '</select>'
        + '</li>';
    $("#new_reservation_which_goal").html(new_reservation_which_goal_html);
	course_list("");
	
	$(".newContentTab").show();
	$(".new_reservation_show").show();
	$(".reservation_detail_show").hide();
	$(".newContentTabCont .no-chatting").show();
	$(".newContentTabCont .comm_cont").hide();
	$(".newContentTabCont .send").hide();
	$(".newContentTabCont3").hide();
	$(".no-member").show();
	$(".no-chatting").show();
	$(".reservation_flow li span").each(function(){
		$(this).addClass("gray");
	})
	$(".newContentTabCont .online").addClass("online-gray");
	$(".newContentTab").css({"z-index" : "200"})
})


$(".reservation_window .assignment").on("click",function(){
	$(".reservation_window").hide();
	$("#new_reservation_school").html(user_school_confirm);
	var new_reservation_which_goal_html = 
		'<li title="GGGGGGGoal"><span class="dis" style="float:left"><span style="color:red">*</span> Goal:</span><input type="text" class="input new_reservation_goal" name="goal" onblur="judgeDigit(this)"></li>';
    $("#new_reservation_which_goal").html(new_reservation_which_goal_html);
    
	course_list("");
	
	$(".newContentTab").show();
	$(".new_reservation_show").show();
	$(".reservation_detail_show").hide();
	$(".newContentTabCont .no-chatting").show();
	$(".newContentTabCont .comm_cont").hide();
	$(".newContentTabCont .send").hide();
	$(".newContentTabCont3").hide();
	$(".no-member").show();
	$(".no-chatting").show();
	$(".reservation_flow li span").each(function(){
		$(this).addClass("gray");
	})
	$(".newContentTab").css({"z-index" : "200"})
})


//new reservation
$(".new_reservation_confirm").on("click",function(){

	var ispublic = $("input:radio[name='ispublic']:checked").val();
	if(ispublic == "public"){
		ispublic = 0;
	}
	else{
		ispublic = 1;
	}
	var administrator = $("input[name='administrator']").is(':checked');
	if(administrator == false){
		administrator = 0;
	}
	else{
		administrator = 1;
	}
	var new_reservation_lecture = "";
	if(user_type == 0){
		new_reservation_lecture = $(".new_reservation_lecture").val();
		if(new_reservation_lecture == null){
			new_reservation_lecture = $("#teacher_detail_name").html();
		}
	}
	else{
		new_reservation_lecture = user_name;
	}
	
	//judge
	var course=$(".new_reservation_course").val();
	var max_size=$(".new_reservation_maximum").val();
	var address=$(".new_reservation_address").val();
	var time=$(".new_reservation_time").val();
	var	period=$(".new_reservation_period").val();
	var goal=$(".new_reservation_goal").val();
	var wage=$(".new_reservation_wage").val();
	var bonus=$(".new_reservation_bonus").val();
	if(course==""||max_size==""||address==""||goal==""||time=="")
	{
		alert("Please input the content with *!");
		return ;
	}
	if(max_size!="" && isNaN(max_size)){
		return ;
	}
	if(period!="" && isNaN(period)){
		return ;
	}
	if(goal!="" && isNaN(goal)){
		return ;
	}
	if(wage!="" && isNaN(wage)){
		return ;
	}
	if(bonus!="" && isNaN(bonus)){
		return ;
	}
	if(new_reservation_lecture!=""){
		flag = 1;
		$.ajax({
			type:"post",
			url:"<%=request.getContextPath()%>/app/judgelecture.htm",
			data:{
				"name":new_reservation_lecture
			},
			async:false,
			success:function(data){
				if(data.data.result == -1){
					flag = 0;
				}
			}
		});
		if(flag == 0){
			return ;
		}
	}
	
	$.ajax({
		type:"get",
		url:"<%=request.getContextPath()%>/app/reservation/apply.htm",
		data:{
			"id":user_id,
			"user_name":user_name,
			"school":user_school_confirm,
			"lecture":new_reservation_lecture,
			"course":course,
			"max_size":max_size,
			"address":address,
			"time":time+":00",
			"period":period,
			"goal":goal,
			"wage":wage,
			"bonus":bonus,
			"ispublic":ispublic,
			"administrator":administrator
		},
		async:false,
		success:function(data){
			console.log(data)
			if(data.code!=0)
			{
				alert(data.message);
			}
			else
			{
				alert("Success for create reservation!");
				$(".newContentTab").hide();
				$(".filterBg").hide();
				reservation_list(user_id, user_school_confirm);
			}
		}
	})
});

function createPromot(_this,_str,result){
	if(result){
	    _this.parent().find(".prompt").remove();
	   return true;
	}
	var str=_str;
	var parent=_this.parent();
	//$(".prompt").remove();
	var promot=$('<div class="prompt">' + '<span>' + '<img src="<%=request.getContextPath()%>/common/images/j1.gif" width="17" height="25">' + '</span>' + str + '</div>');
	promot.appendTo(parent);
	$(".prompt").animate({
		"opacity" : 1
	});
	return false;
}

function judgeDigit(_this_){
	var _this=$(_this_);
	var val=_this.val();
	if(val!=''){
		if(isNaN(val)){
			var str="Must all digits!";
			return createPromot(_this,str);
		}
		else{			
			return createPromot(_this,str,true);
		}
	}
	else{
		return createPromot(_this,str,true);
	}
}

function new_lecture_search(_this_){
	var _this=$(_this_);
	var val=_this.val();
	var str = "";
	if(val!=''){
		$.ajax({
			type:"post",
			url:"<%=request.getContextPath()%>/app/judgelecture.htm",
			data:{
				"name":val
			},
			async:false,
			success:function(data){
				if(data.data.result == -1){
					str="Lecture not exist!";
					return createPromot(_this,str);
				}
				else{
					course_list(val);
					return createPromot(_this,str,true);
				}
			}
		});
	}
	else{
		course_list(val);
		return createPromot(_this,str,true);
	}
}
$("#Bonusyes").on("click",function(){
	$("#BonusInput").show();
})
$("#Bonusno").on("click",function(){
	$("#BonusInput").hide();
})

//reservation_detail
function reservation_join(user_id, reservation_id, wage, period){
  	$.ajax({
		type:"post",
		url:"<%=request.getContextPath()%>/app/reservation/join.htm",
		data:{
			"user_id":user_id,
			"reservation_id":reservation_id,
			"wage":wage,
			"period":period
		},
		async:false,
		success:function(data){
			alert(data.data.result);
		}
	});
}

function reservation_detail(user_id, reservation_id){
	$(".appley_for_teacher").hide();
	$(".dropOut").hide();
  	$.ajax({
		type:"get",
		url:"<%=request.getContextPath()%>/app/user/reservationdetail.htm",
		data:{
			"user_id":user_id,
			"reservation_id":reservation_id,
			"limit":-1,
			"offset":-1
		},
		async:false,
		success:function(data){
			var re = data.data.reservationdetail;
			var price1 = re.reservation_detail_period * re.reservation_detail_wage;
			var price2 = re.reservation_detail_bonus;
			var reservation_number = re.reservation_detail_number;
			var reservation_detail_lecture_avatar = re.reservation_detail_lecture_avatar;
			$("#reservation_detail_reservation_number").html(reservation_number);
			$("#reservation_detail_school").html(re.reservation_detail_school);
			$("#reservation_detail_lecture").html(re.reservation_detail_lecture_name);
			$("#reservation_detail_course").html(re.reservation_detail_course);
			$("#reservation_detail_max_size").html(re.reservation_detail_max_size);
			$("#reservation_detail_address").html(re.reservation_detail_address);
			$("#reservation_detail_time").html(jsonDateFormat(String(re.reservation_detail_time.time)));
			$("#reservation_detail_period").html(re.reservation_detail_period);
			$("#reservation_detail_goal").html(re.reservation_detail_goal);
			$("#reservation_detail_wage").html(re.reservation_detail_wage);
			$("#reservation_detail_bonus").html(re.reservation_detail_bonus);
			var is_public = "";
			if(re.reservation_detail_ispublic == 0)
			{
				is_public = "Public";
			}
			else{
				is_public = "Private";
			}
			$("#reservation_detail_ispublic").html(is_public);
			
			if(data.data.user_reservation_status == 0){
				if($("#reservation_detail_exit").hasClass("exit1") == true){
					$("#reservation_detail_exit").removeClass("exit1");
				}
				if($("#reservation_detail_exit").hasClass("exit") == false){
					$("#reservation_detail_exit").addClass("exit");
				}
			}
			else{
				if($("#reservation_detail_exit").hasClass("exit") == true){
					$("#reservation_detail_exit").removeClass("exit");
				}
				if($("#reservation_detail_exit").hasClass("exit1") == false){
					$("#reservation_detail_exit").addClass("exit1");
				}
			}
			if(data.data.user_reservation_status == -1){
				$(".reservation_detail_evaluate_page").hide();
				if(re.reservation_detail_status >= 3){
					$(".reservation_detail_button").hide();
					$(".reservation_detail_writting").show().text("The class has begun!");
				}
				else{
					$(".reservation_detail_button").show();
					$(".reservation_detail_writting").hide();
					if(user_type == 0){
						$(".reservation_detail_button").attr("value","JOIN IT").attr("id","reservation_student_join");
						$("#reservation_student_join").unbind("click").on("click",function(){
							reservation_join(user_id, reservation_id, -1, -1);
							reservation_detail(user_id, reservation_id);
						});
					}
					else{
						$(".reservation_detail_button").attr("value","TO BE THE LECTURE").attr("id","reservation_lecture_join");
						$("#reservation_lecture_join").unbind("click").on("click",function(){
							$(".appley_for_teacher").show();
							$(".filterBg").css({"z-index":"101"})
							$("#apply_for_teacher_submit").unbind("click").on("click",function(){
								var wage = $("#apply_for_teacher_wage").val();
								var period = $("#apply_for_teacher_period").val();
								if(wage == "" || period == ""){
									alert("Can not be empty!");
									return false;
								}
								if(isNaN(wage) || isNaN(period)){
									alert("Must be all digits!");
									return false;
								}
								reservation_join(user_id, reservation_id, wage, period);
								reservation_detail(user_id, reservation_id);
							})
							
						});
					}
				}
			}
			else if(data.data.user_reservation_status == 0){
				$(".reservation_detail_evaluate_page").hide();
				$(".reservation_detail_button").show().attr("value","AGREE").attr("id","reservation_agree");
				$(".reservation_detail_writting").hide();
				$("#reservation_agree").unbind("click").on("click",function(){
					$.ajax({
						type:"post",
						url:"<%=request.getContextPath()%>/app/reservation/agree.htm",
						data:{
							"user_id":user_id,
							"reservation_id":reservation_id
						},
						async:false,
						success:function(data){
							alert(data.data.result);
						}
					});
					reservation_detail(user_id, reservation_id);
				});
			}
			else if(data.data.user_reservation_status == 1){
				$(".reservation_detail_evaluate_page").hide();
				if(re.reservation_detail_status == 0){
					$(".reservation_detail_button").hide();
					$(".reservation_detail_writting").show().text("Waiting for others to agree!");
				}
				else if(re.reservation_detail_status == 1){
					$(".reservation_detail_button").show().attr("value","PAY").attr("id","ev_pay");
					$(".reservation_detail_writting").hide();
					$("#ev_pay").unbind("click").on("click",function(){
						$.ajax({
							type:"post",
							url:"<%=request.getContextPath()%>/app/reservation/pay.htm",
							data:{
								"user_id":user_id,
								"reservation_id":reservation_id,
							},
							async:false,
							success:function(data){
								alert(data.data.result);
							}
						});
						
						reservation_detail(user_id, reservation_id);
					});
				}
			}
			else if(data.data.user_reservation_status == 2){
				$(".reservation_detail_evaluate_page").hide();
				if(re.reservation_detail_status == 1){
					$(".reservation_detail_button").hide();
					$(".reservation_detail_writting").show().text("Waiting for others to pay!");
				}
				else if(re.reservation_detail_status == 2){
					if(re.reservation_detail_create_id == user_id){
						$(".reservation_detail_button").show().attr("value","BEGIN").attr("id","reservation_begin");
						$(".reservation_detail_writting").hide();
						$("#reservation_begin").unbind("click").on("click",function(){
							$.ajax({
								type:"post",
								url:"<%=request.getContextPath()%>/app/reservation/begin.htm",
								data:{
									"reservation_id":reservation_id
								},
								async:false,
								success:function(data){
									alert(data.data.result);
									reservation_detail(user_id, reservation_id);
								}
							});
						});
					}
					else{
						$(".reservation_detail_button").hide();
						$(".reservation_detail_writting").show().text("Waiting for class to begin!");
					}
				}
			}
			else if(data.data.user_reservation_status == 3){
				$(".reservation_detail_evaluate_page").hide();
				if(re.reservation_detail_status == 3){
					if(re.reservation_detail_create_id == user_id){
						$(".reservation_detail_button").show().attr("value","FINISH").attr("id","reservation_finish");
						$(".reservation_detail_writting").hide();
						$("#reservation_finish").unbind("click").on("click",function(){
							$.ajax({
								type:"post",
								url:"<%=request.getContextPath()%>/app/reservation/finish.htm",
								data:{
									"reservation_id":reservation_id
								},
								async:false,
								success:function(data){
									alert(data.data.result);
									reservation_detail(user_id, reservation_id);
								}
							});
						});
					}
					else{
						$(".reservation_detail_button").hide();
						$(".reservation_detail_writting").show().text("The class has begun!");
					}
				}
			}
			else if(data.data.user_reservation_status == 4){
				if(re.reservation_detail_status == 4){
					$(".reservation_detail_button").hide();
					$(".reservation_detail_writting").show().text("The class has finished!");
					$(".reservation_detail_evaluate_page").show();
				}
			}
			else if(data.data.user_reservation_status == 5){
				$(".reservation_detail_button").hide();
				$(".reservation_detail_writting").show().text("The class has finished!");
				$(".reservation_detail_evaluate_page").hide();
			}
			var status = re.reservation_detail_status;
			$(".newContentTabCont .online").removeClass("online-gray");
			for(var i = 0; i < status-1; i++){
				$(".reservation_flow li span").eq(i).removeClass("gray");
			}
			for(var i = Math.max(status-1,0); i < 4; i++){
				$(".reservation_flow li span").eq(i).addClass("gray");
			}		
			
			$("#reservation_detail_exit").unbind("click").on("click",function(){
				if($("#reservation_detail_exit").hasClass("exit") == true){
					$(".dropOut").show().css({"z-index" : "999"});
					$(".filterBg").show();
					$(".filterBg").css({"z-index" : "150"});
				}
			})
			
			$("#drop_out").unbind("click").on("click",function(){
				$.ajax({
					type:"post",
					url:"<%=request.getContextPath()%>/app/reservation/drop_out.htm",
					data:{
						"user_id":user_id,
						"reservation_id":reservation_id,
					},
					async:false,
					success:function(data){
						//alert(data.data.result);
						$(".dropOut").hide();
						$(".evaluate_pay").animate({
							 "top" : "100%",
							 "left":"100%",
							 "hiehgt" : "0"
						 });
						$(".evaluate_pay").hide();
						$(".evaluate_pay").css({
							"margin-top": "-150px", "margin-left": "-350px","height" : "700px"
						})
						$(".filterBg").hide();
					}
				});
			});
			
			//evaluate
			$("#evaluate_yes").unbind("click").on("click",function(){
				var user_name = '<%=us.getUser_name() %>';
				if(re.reservation_detail_lecture == user_name){
					$.ajax({
						type:"post",
						url:"<%=request.getContextPath()%>/app/reservation/student_list.htm",
						data:{
							"reservation_id":reservation_id,
							"limit":-1,
							"offset":-1
						},
						async:false,
						success:function(data){
							var a = data.data.avatar;
							var evaluate_page_teacher_list_html = "";
							for(var i = 0; i < a.length; i++){
								evaluate_page_teacher_list_html = evaluate_page_teacher_list_html
								+ '<li><span><img src="<%=request.getContextPath()%>/'
								+ a[i].avatar_url + '" class="photo"></span>'
								+ '<input type="hidden" class="avatar_user_id" value="' + a[i].avatar_user_id + '"/>'
								+ '<textarea name="" cols="" rows="" class="textarea"></textarea>'
								+ '<span class="glyphicon glyphicon-thumbs-up"></span><span class="glyphicon glyphicon-thumbs-down"></span></li>';
							}
							$("#evaluate_page_teacher_list").html(evaluate_page_teacher_list_html);
							$(".evaluate_praise_list .glyphicon").unbind("click").on("click",function(){
								if(!$(this).hasClass("on")){
									var flag = 0;
									if($(this).hasClass("glyphicon-thumbs-up")){
										if($(this).next().hasClass("on")){
											flag = 1;
										}
									}
									else{
										if($(this).prev().hasClass("on")){
											flag = 1;
										}
									}
									if(flag == 0){
										$(this).addClass("on");
									}
								}else{
									$(this).removeClass("on");
								}
							});
						}
					});
					$("#evaluate_page_teacher").show();
					$("#evaluate_page_teacher_submit").unbind("click").on("click",function(){
						var evaluate_teacher_content = "[";
						var index = 0;
						$("#evaluate_page_teacher_list li").each(function(){
							if(index > 0){
								evaluate_teacher_content += ",";
							}
							var up = 0;
							var down = 0;
							if($(this).find(".glyphicon-thumbs-up").hasClass("on")){
								up = 1;
							}
							if($(this).find(".glyphicon-thumbs-down").hasClass("on")){
								down = 1;
							}
							evaluate_teacher_content = evaluate_teacher_content
							+ '{"student_id":"' + $(this).find(".avatar_user_id").attr("value") + '",'
							+ '"content":"' + $(this).find(".textarea").val() + '",'
							+ '"up":"' + up + '",'
							+ '"down":"' + down + '"}';
							index++;
						});
						evaluate_teacher_content += ']';
						$.ajax({
							type:"post",
							url:"<%=request.getContextPath()%>/app/reservation/evaluateteacher.htm",
							data:{
								"teacher_id":user_id,
								"reservation_id":reservation_id,
								"evaluation":evaluate_teacher_content
							},
							async:false,
							success:function(data){
								alert("Success for evaluate!");
								$("#evaluate_page_teacher").hide();
								reservation_detail(user_id, reservation_id, user_type, user_name);
							}
						});
					});
				}
				else{
					$(".evaluate_page .evaluate_head .photo").attr("src", "<%=request.getContextPath()%>/"+reservation_detail_lecture_avatar);
					$(".reservation_detail_evaluate_page").hide();
					$("#evaluate_page_student").show();
					$("#evaluate_page_student_submit").unbind("click").on("click",function(){
						var patience = $("#evaluate_page_student_pat").attr("value");
						var professionalism = $("#evaluate_page_student_pro").attr("value");
						var expression = $("#evaluate_page_student_exp").attr("value");
						var usefulness = $("#evaluate_page_student_use").attr("value");
						var interaction = $("#evaluate_page_student_int").attr("value");
						var content = $("#evaluate_page_student_content").html();
						var isgoal = -1;
						$("#evaluate_reach_goal").show();
						$(".dropOut2 .no").unbind("click").on("click",function(){
							isgoal = 0;
							$(this).parents(".dropOut2").hide();
							evaluate_student(user_id, reservation_id, patience
							, professionalism, expression, usefulness, interaction,
							content, isgoal);
							reservation_detail(user_id, reservation_id, user_type, user_name);
						});
						$(".dropOut2 .yes").unbind("click").on("click",function(){
							isgoal = 1;
							$(this).parents(".dropOut2").hide();
							evaluate_student(user_id, reservation_id, patience
							, professionalism, expression, usefulness, interaction,
							content, isgoal);
							reservation_detail(user_id, reservation_id, user_type, user_name);
						});
					});
				}
			});
			$("#evaluate_no").unbind("click").on("click",function(){
				$.ajax({
					type:"post",
					url:"<%=request.getContextPath()%>/app/reservation/finish_evaluate.htm",
					data:{
						"user_id":user_id,
						"reservation_id":reservation_id
					},
					async:false,
					success:function(data){
						$(".reservation_detail_evaluate_page").hide();
						reservation_detail(user_id, reservation_id, user_type, user_name);
					}
				});
			});
			
			$("#reservation_chat_send").unbind("click").on("click", function(){
				var cVal=$("#reservation_chat_content").val();
				if(cVal=="Leave a message?"||cVal==""){
					return;
				}
				
				addClassroomRemind(reservation_id, user_id);
				
				var content = $("#reservation_chat_content").val();
				var to_user_name = "";
				if(content.split(":")[0] != content) to_user_name = content.split(":")[0].split("@")[1]
				$.ajax({
					type:"post",
					url:"<%=request.getContextPath()%>/app/classroom/chat_send.htm",
					data:{
						"reservation_id":reservation_id,
						"user_id":user_id,
						"content":content,
						"to_user_name":to_user_name
					},
					async:false,
					success:function(data){
						reservation_chat_list(reservation_id);
						$("#reservation_chat_content").val("");
						var rHeight=$("#reservation_chat_list").height();
						$(".comm_cont").scrollTop(rHeight + 30);
					}
				});
			});
			
			//teacher_evaluate_list
			$.ajax({
				type:"post",
				url:"<%=request.getContextPath()%>/app/reservation/totalevaluationteacher.htm",
				data:{
					"id":reservation_id,
				},
				async:false,
				success:function(data){
					if(data.code != 0){
						$(".evaluate_big_cont").html('<div class="no-evaluation" style="clear:both">There is no evaluation yet</div>');
						return ;
					}
					tet = data.data.teacher_evaluation_total;
					$("#evaluate_page_teacher_all_pat").text(tet.average_patience);
					$("#evaluate_page_teacher_all_pat_1").css("width", tet.average_patience+"%");
					$("#evaluate_page_teacher_all_pro").text(tet.average_professionalism);
					$("#evaluate_page_teacher_all_pro_1").css("width", tet.average_professionalism+"%");
					$("#evaluate_page_teacher_all_exp").text(tet.average_expression);
					$("#evaluate_page_teacher_all_exp_1").css("width", tet.average_expression+"%");
					$("#evaluate_page_teacher_all_use").text(tet.average_usefulness);
					$("#evaluate_page_teacher_all_use_1").css("width", tet.average_usefulness+"%");
					$("#evaluate_page_teacher_all_int").text(tet.average_interaction);
					$("#evaluate_page_teacher_all_int_1").css("width", tet.average_interaction+"%");
					evaluate_page_teacher_all_list_html = "";
					for(var i = 0; i < tet.evaluate_student.length; i++){
						var es = tet.evaluate_student[i];
						evaluate_page_teacher_all_list_html = evaluate_page_teacher_all_list_html
						+ '<div class="left"><img src="<%=request.getContextPath()%>/'
						+ es.user_avatar + '" class="photo"> ' + es.user_name + '</div>'
						+ '<div class="right" style="width:510px"><div class="eva_text">' + es.content + '</div><div class="">'
						+ '<ul class="evaluate_com_list evaluate_com_listOn" style="display:block">'
						+ '<li><div class="t">Patience:</div><div class="outer"><div class="inner" style="width:' + es.patience + '%"></div>'
						+ '</div><div class="n">' + es.patience + '</div></li>'
						+ '<li><div class="t">Professionalism:</div><div class="outer"><div class="inner" style="width:' + es.professionalism + '%"></div>'
						+ '</div><div class="n">' + es.professionalism + '</div></li>'
						+ '<li><div class="t">Expression:</div><div class="outer"><div class="inner" style="width:' + es.expression + '%"></div>'
						+ '</div><div class="n">' + es.expression + '</div></li>'
						+ '<li><div class="t">Usefulness:</div><div class="outer"><div class="inner" style="width:' + es.usefulness + '%"></div>'
						+ '</div><div class="n">' + es.usefulness + '</div></li>'
						+ '<li><div class="t">Interaction:</div><div class="outer"><div class="inner" style="width:' + es.interaction + '%"></div>'
						+ '</div><div class="n">' + es.interaction + '</div></li>' + '</ul>' 
						+ '</div></div>';
						$("#evaluate_page_teacher_all_list").html(evaluate_page_teacher_all_list_html);
					}
				}
			});
			
			
			//member
			$.ajax({
				type:"get",
				url:"<%=request.getContextPath()%>/app/classroom/member.htm",
				data:{
				    "id":reservation_id,
				    "limit":-1,
				    "offset":-1
				},
				async:false,
				success:function(data){
				    var m = data.data.member;
				    //teacher
				    var reservation_detail_lecture_list_html = "";
				    for(var i = 0; i < m.length; i++){
				    	if(m[i].member_type == 1 && m[i].member_user_id == re.reservation_detail_lecture_id){
					    	reservation_detail_lecture_list_html = reservation_detail_lecture_list_html
					    	+ '<li><span class="photo"><img src="<%=request.getContextPath()%>/' + m[i].member_avatar_url + '"></span>'
					    	+ '<div class="text">'
					    	+ '<p class="name">' + m[i].member_name + '</p>'
					    	+ '<p class="number">' + m[i].member_telephone + '</p>'
					    	+ '</div>'
					    	+ '<input type="hidden" id="classroom_teacher_id" value="' + m[i].member_user_id + '"/>'
					    	+ '<div class="slid">'
					    	+ '<span class="glyphicon glyphicon-chevron-down slid-up lecture_evaluate_up"></span>'
					    	+ '<span class="glyphicon glyphicon-chevron-up slid-down lecture_evaluate_down" style="display:none"></span>'
					    	+ '</div>'
					    	+ '</li>';
					    }
				    }
				    $("#reservation_detail_lecture_list").html(reservation_detail_lecture_list_html);
				    
				    $("#reservation_detail_lecture_list .photo").unbind("click").on("click",function(){
				    	var teacher_id = $(this).parent().find("input").val();
				    	teacher_detail(teacher_id, user_id);
				    })
				    
				    //student
				    var reservation_detail_student_list_html = "";
				    for(var i = 0; i < m.length; i++){
				    	if(m[i].member_type == 0){
				    		var teacher_avatar = "";
				    		var content = "";
				    		var on = 0;
				    		var flag = 0;
				    		
				    		$.ajax({
								type:"post",
								url:"<%=request.getContextPath()%>/app/reservation/totalevaluationstudent.htm",
								data:{
									"user_id":m[i].member_user_id,
									"reservation_id":reservation_id,
								},
								async:false,
								success:function(data){
									if(data.code != 0){
										return ;
									}
									set = data.data.student_evaluation_total;
									flag = 1;
									teacher_avatar = "<%=request.getContextPath()%>/"+set.teacher_avatar;
									content = set.content
									if(set.up == 1) on = 1;
									else on = 0;
								}
							})
				    	
					    	reservation_detail_student_list_html = reservation_detail_student_list_html
					    	+ '<li><span class="photo"><img src="<%=request.getContextPath()%>/' + m[i].member_avatar_url + '"></span>'
					    	+ '<div class="text">'
					    	+ '<p class="name">' + m[i].member_name + '</p>'
					    	+ '<p class="number">' + m[i].member_telephone + '</p>'
					    	+ '</div>'
					    	+ '<input type="hidden" class="classroom_student_id" value="' + m[i].member_user_id + '"/>'
					    	+ '<div class="slid">'
					    	+ '<span class="glyphicon glyphicon-chevron-down slid-up student_evaluate_up"></span>'
					    	+ '<span class="glyphicon glyphicon-chevron-up slid-down student_evaluate_down" style="display:none"></span>'
					    	+ '</div>';
					    	if(flag == 1){
					    		reservation_detail_student_list_html = reservation_detail_student_list_html
					    		+ '<div class="evaluate_praise_list" style="display:none">'
						    	+ '<span><img src=' + teacher_avatar + ' class="photo"></span>'
						    	+ '<span class="tap">' + content + '</span>';
						    	if(on == 1){
						    		reservation_detail_student_list_html = reservation_detail_student_list_html
						    		+ '<span class="glyphicon glyphicon-thumbs-up on"></span><span class="glyphicon glyphicon-thumbs-down"></span>'
						    	}
						    	else{
						    		reservation_detail_student_list_html = reservation_detail_student_list_html
						    		+ '<span class="glyphicon glyphicon-thumbs-up"></span><span class="glyphicon glyphicon-thumbs-down on"></span>'
						    	}
						    	reservation_detail_student_list_html = reservation_detail_student_list_html
						    	+ '</div>'
					    	}
					    	else{
					    		reservation_detail_student_list_html = reservation_detail_student_list_html
					    		+ '<div class="no-evaluation" style="clear:both;display:none">There is no evaluation yet</div>';
					    	}
					    	reservation_detail_student_list_html = reservation_detail_student_list_html
					    	+ '</li>';
					    }
				    }
				    $("#reservation_detail_student_list").html(reservation_detail_student_list_html);
				    
				     $("#reservation_detail_student_list .photo").unbind("click").on("click",function(){
				    	var student_id = $(this).parent().find("input").val();
				    	friend_detail(student_id);
				    })
				    
				    $(".lecture_evaluate_up").unbind("click").on("click",function(){
						$(this).hide();
						$(this).siblings().show();
						$(".evaluate_big_cont").show();
					})
					$(".lecture_evaluate_down").unbind("click").on("click",function(){
						$(this).hide();
						$(this).siblings().show();
						$(".evaluate_big_cont").hide();
					})
					$(".student_evaluate_up").unbind("click").on("click",function(){
						$(this).hide();
						$(this).siblings().show();
						$(this).parent().next().height("auto").show();
					})
					$(".student_evaluate_down").unbind("click").on("click",function(){
						$(this).hide();
						$(this).siblings().show();
						$(this).parent().next().height("0").hide();
					})
				}
			})
		}
	});
	
	
	
	$(".filterBg").show();
	$(".filterBg").css({"z-index" : "50"});
	$(".newContentTab").show();
	$(".new_reservation_show").hide();
	$(".reservation_detail_show").show();
	$(".newContentTabCont3").show();
	$(".no-member").hide();
	$(".no-chatting").hide();
}

</script>